using UnityEngine;
using System.Collections;

public class ItemScript : MonoBehaviour {
	
	public int healthValue = 1;
	public float boostValue = 0.6F;
	
	private bool inPlace = false;
	private Transform m_transform;
	private Vector3 m_restingPlace;
	private int MOVESPEED = 3;
	private int STOPDISTANCE = 1;

	// Use this for initialization
	void Start () {
		m_transform = transform;
		//m_rigidbody = m_transform.GetComponent<Rigidbody>();
		m_transform.Rotate(Vector3.right * 90);
		m_transform.Rotate(Vector3.up * 180);
	}
	
	// Update is called once per frame
	void Update () {
		if(!inPlace)
		{
			float transY = transform.rigidbody.position.y;
			transform.rigidbody.position = new Vector3(transform.rigidbody.position.x, transY - (Time.deltaTime * MOVESPEED), transform.rigidbody.position.z);
			if(transform.rigidbody.position.y <= STOPDISTANCE)
			{
				inPlace = true;
			}
		} else if (m_transform.position.y > m_restingPlace.y + 5) { inPlace = false; }
		
		if(m_transform.position.y <= m_restingPlace.y)
		{
			inPlace = true;
		}
	}
	

	
	void OnEnable()
	{
		//add my listeners	
		Messenger<string>.AddListener("reset", ResetAsset);
	}
	
	void OnDisable()
	{
		//disable listeners
		Messenger<string>.RemoveListener("reset", ResetAsset);
	}
	
	void ResetAsset(string winner){
		PoolManager.Pools["PowerUps"].Despawn(transform);
	}
}
